Monocle.Controls.Keyboard = function (reader) {
  if (Monocle.Controls == this) {
    return new Monocle.Controls.Keyboard(reader);
  }

  var API = {constructor: Monocle.Controls.Keyboard}
  var k = API.constants = API.constructor;
  var p = API.properties = {
    reader: reader
  }
  
  function listen() {
      document.addEventListener("keydown", function(e){
            //Scroll left by arrow movement
            if(e.which==37) {
                console.log(p.reader.getPlace());
                p.reader.moveTo({ page: p.reader.getPlace().pageNumber() - 1});
            }

            //Scroll right by arrow movement
            if(e.which==39){
                p.reader.moveTo({ page: p.reader.getPlace().pageNumber() + 1});
            }
        }, false);
  }
  
  API.listen = listen;
  
  return API;
}

Monocle.pieceLoaded('controls/keyboard');
